A module doesn't have to do anything in itself, in this example we are just
using it as a convenient way to add scripts/commands to the popup menu for
certain filetypes.
This script is taken straight from my DOpus5:Modules/ directory, so a bit
of explaining about my filetypes setup might be necessary first, before you
can see how it can work.
I have filetypes for many different archives, for example: LhA, LZX, DMS,
GZIP, HPACK, TAR, ARJ, RAR, OWS, ZIP, ARC...
For the archives I just mentioned, most people would have the filetype IDs
as: LHA, LZX, DMS, GZIP, HPACK, TAR, ARJ, RAR, OWS, ZIP, ARC...
The way my filetype IDs for the above are set up is: aLHA, aLZX, aDMS,
aGZP, aHPK, aTAR, aARJ, aRAR, aOWS, aZIP, aARC... That is, a lower case 'a'
followed by three letters signifying the archive type.
You might think this is a bit strange, but where it is extremely useful is
in the adding of menuitems and similar. For example, for all of my archive
filetypes I have 'User4' defined as the 'Test archive' function. So that
whenever I call 'User4' on any type of archive, I know that will test it with
the appropriate archiver.
If you wanted to add a 'Test' menuitem to the popup menu for each type of
archive, you would have to go into the Filetype Editor for each one and add
it to the Icon popup menu.
Or, if you were going to do it as per below, you would need to change this
line:
dopus command "Test" program "General" 'source' ext 'Test...' type a??? private
to this:
dopus command "Test" program "General" 'source' ext 'Test...' type LHA type LZX type DMS private
adding in every archiver ID you have, as you can see you will end up with a
very long line.
I, on the other hand, would just include a line like you can see below:
dopus command "Test" program "General" 'source' ext 'Test...' type a??? private
Using the wildcard feature for specifying a 'type', I have just added a
'Test' menuitem to every archive filetype.
Much easier ;-)
I also use the same system for pictures, (p????), and documents, (d????).
On with the example:
1 /*
2 $VER: General.dopus5 1.0 (10.07.96)
3
4 This module adds the following things:
5
6 Adds a 'Browse...' command to the popup menu for LhA and LZX archives.
7 Adds a 'GetDir...' command to the popup menu for LhA and LZX archives.
8 Adds an 'UnDMS...' command to the popup menu for DMS archives.
9 Adds a 'Test...' command to the popup menu for ALL archives.
10 Adds a 'Container' command to the popup menu for left-out files/dirs.
11
12 Requirements:
13
14 Needs ArcDir.dopus5 and UnDMS.dopus5 installed, both by Edmund Vermeulen.
15 */
16 parse arg portname function srce dest filename .
17 address value portname
18 options results
19
20 /* Initialise */
21 if function = 'init' then
22 do
23 dopus command "Browse" program "General" 'source' ext 'Browse...' type aLHA type aLZX private
24 dopus command "GetDir" program "General" 'source' ext 'GetDir...' type aLHA type aLZX private
25 dopus command "UnDMS" program "General" 'source' ext 'UnDMS...' type aDMS private
26 dopus command "Test" program "General" 'source' ext 'Test...' type a??? private
27 dopus command "Container" program "General" ext "'Open Container'" type leftout private
28 exit
29 end
30 if function = 'Browse' then dopus rx 'DOpus5:ARexx/ArcDir.dopus5 Browse' portname filename srce
31 if function = 'GetDir' then dopus rx 'DOpus5:ARexx/ArcDir.dopus5 GetDir' portname filename srce
32 if function = 'UnDMS' then dopus rx 'DOpus5:ARexx/UnDMS.dopus5' filename portname
33 if function = 'Test' then command User4 filename
34 if function = 'Container' then command scandir new container filename
35 exit
What it all means:
Lines:
1-15 Mandatory ARexx comment with version information, what it does and
what it requires.
16 As shown in the previous module examples, Opus will pass along these
five parameters to the module: Opus ARexx port, the function, the
SOURCE handle, the DESTINATION handle and any arguments, (in this
case the name of the file whose popup menu we used).
17-18 We address the passed portname, (usually DOPUS.1), and enable
results.
21 As shown in the previous examples, when Opus first calls the module,
it will call it with a function of 'init' to initialise the commands
that you're adding.
23 This 'dopus command' line adds the command 'Browse', the program
that will be called is 'General.dopus5', (that is, the one above).
We will require the SOURCE handle, the text that will appear in the
menus is 'Browse...' and we only want it to appear for files with a
filetype ID of 'aLHA' and 'aLZX', (yours are probably 'LHA' and 'LZX'
unless you've changed them like I have). The 'private' flag
specifies that this command will not appear in the internal command
list.
24 Same as for line 23 except here we add the command 'GetDir'.
25 In this line we add the command 'UnDMS' but only for a filetype ID
of 'aDMS', (a DMS archive).
26 This line is where we add the 'Test' command to all filetype IDs
that match the pattern 'a???', on my system this is all archive
filetypes.
27 This adds the 'Container' command to all left-out files/dirs on the
Desktop.
28 We exit because the 'init' function is finished.
The next time this module will be called, will be when the user has chosen
a menuitem from a file/dir popup menu that corresponds to one which we have
added, therefore:
30 'Browse...' was selected from the menu over a LhA or LZX archive,
this line will call Edmund's ArcDir.dopus5 script passing along the
command 'BROWSE', the Opus port name, the filename and the handle of
the lister.
31 'GetDir...' was selected from the menu over a LhA or LZX archive,
this line will call Edmund's ArcDir.dopus5 script passing along the
command 'GETDIR', the Opus port name, the filename and the handle of
the lister.
32 'UnDMS...' was selected from the menu over a DMS archive, this line
will call Edmund's UnDMS.dopus5 script passing along the filename
and the Opus port name.
33 'Test...' was selected from the menu over any archive, this line
will call the 'User4' function for that filename, (the 'Test
archive' function in my filetypes).
34 'Open Container' was selected from a left-out popup menu, this will
call the Opus ScanDir command. The 'file new container' parameters
specify that: a new lister will open in that files home directory
with that file selected.
35 We exit.
|